package cn.mw.cmdb.entity.FinanceReport;

import cn.mw.cmdb.entity.PropertyTypeString;
import cn.mw.cmdb.util.DataCreateInfo;
import cn.mw.components.mongodb.anno.AutoId;
import cn.mw.components.mongodb.anno.CMDBProperty;
import cn.mw.microMonitorCommon.api.cmdb.TreeView;
import cn.mw.microMonitorCommon.api.cmdb.TreeViewType;
import com.alibaba.nacos.common.utils.CollectionUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.util.List;

@Data
@Document("mw_cmdbmd_finance_report_group")
public class FinanceReportGroupInfo implements DataCreateInfo, TreeView, Serializable {

    @CMDBProperty(searchType = PropertyTypeString.ID, searchPrefix = "_")
    @AutoId
    @Schema(description = "id")
    private String id;

    @Schema(description = "上报通道ID")
    @CMDBProperty(searchType = PropertyTypeString.ID)
    private Integer channelId;

    @Schema(description = "分组名")
    @CMDBProperty
    private String name;

    @Schema(description = "上级分组ID")
    @CMDBProperty
    private String parentGroupId;

    @Schema(description = "分组路径")
    @CMDBProperty
    private List<String> groupPath;

    @Transient
    private int count;

    public void setGroupPath(List<String> groupPath) {
        this.groupPath = groupPath;
        if (CollectionUtils.isNotEmpty(groupPath)) {
            this.parentGroupId = groupPath.get(groupPath.size() - 1);
        }
    }

    @Override
    public Object getParentId() {
        return this.parentGroupId;
    }

    @Override
    public String getItemName() {
        return this.name;
    }

    @Override
    public String getType() {
        return TreeViewType.custom.name();
    }

    @Override
    public String getViewType() {
        return null;
    }
}
